import 'package:flutter/material.dart';
import 'package:flutter_mwm/impl/ui.dart';
import 'package:flutter_mwm/util/util.dart';
import 'package:flutter_mwm/widget/dialog.dart';

abstract class BaseWidget<T extends StatefulWidget> extends StatefulWidget {
  final Key key;

  const BaseWidget({this.key}) : super(key: key);
}

abstract class StateBase<T extends BaseWidget> extends State<T> with UIImpl {
  @override
  void showToast(String content) {
    ToastUtil.show(context, TextUtils.replace(content, ''));
  }

  @override
  void showPromptDialog(String content,
      {String btnText,
      bool exit = false,
      bool outsideDismiss = true,
      VoidCallback callback}) {
    showErrorPromptDialog(content, null,
        btnText: btnText,
        exit: exit,
        outsideDismiss: outsideDismiss,
        callback: callback);
  }

  @override
  void showErrorPromptDialog(String content, String error,
      {String btnText,
      bool exit = false,
      bool outsideDismiss = true,
      VoidCallback callback}) {
    String _content = TextUtils.replace(content, '');
    String _error = TextUtils.replace(error, '');
    String _message =
        TextUtils.isEmpty(_content) ? '$_content$_error' : '$_content\n$_error';

    PromptDialog.show(context, _message,
        btnText: btnText,
        exit: exit,
        outsideDismiss: outsideDismiss,
        callback: callback);
  }

  @override
  void showOperateDialog(
    String content, {
    String cancelText,
    String nextText,
    bool exit = false,
    bool outsideDismiss = true,
    Operate operate,
    VoidCallback cancelCall,
    VoidCallback nextCall,
  }) {
    OperateDialog(
      context,
      TextUtils.replaceNull(content),
      cancelText: cancelText,
      nextCall: nextCall,
      nextText: nextText,
      cancelCall: cancelCall,
      operate: operate,
      exit: exit,
      outsideDismiss: outsideDismiss,
    ).show();
  }
}
